#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


struct cmp
{
    bool operator()(pair<int, int> x1, pair<int, int> x2)
    {
        return x1.first < x2.first;
    }
}cmp;

int main() {
    vector<pair<int, int>> board;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        board.push_back({ x,y });
    }
    sort(board.begin(), board.end(), cmp);
    int ret = 0;
    int prev = 0;
    for (int i = 0; i < n; i++)
    {
        if (board[i].first < prev)
        {
            prev = min(prev, board[i].second);
        }
        else
        {
            ret++;
            prev = board[i].second;
        }
    }
    cout << ret << endl;
    return 0;
}

int main() {
    string str;
    cin >> str;
    int arr[26] = { 0 };
    int n = str.size();
    int left = 0;
    int right = 0;
    int length = 0;
    int l = 0;
    while (right < n)
    {
        if (arr[str[right] - 'a'] == 0)
        {
            l++;
        }
        arr[str[right] - 'a']++;
        while (l > 2)
        {
            arr[str[left] - 'a']--;
            if (arr[str[left] - 'a'] == 0)
            {
                l--;
            }
            left++;
        }
        length = max(length, right - left + 1);
        right++;
    }
    cout << length << endl;
    return 0;
}

class Solution {
public:
    vector<string> ret;
    int n;
    bool board[10] = { false };

    void beal(string& str, string prev)
    {
        if (prev.size() == n)
        {
            int k = ret.size();
            for (int i = 0; i < k; i++)
            {
                if (ret[i] == prev)
                {
                    return;
                }
            }
            ret.push_back(prev);
        }
        for (int i = 0; i < n; i++)
        {
            if (!board[i])
            {
                board[i] = true;
                beal(str, prev + str[i]);
                board[i] = false;
            }
        }
    }

    vector<string> Permutation(string str) {
        // write code here
        n = str.size();
        beal(str, "");
        return ret;
    }
};

int main() {
    int n;
    cin >> n;
    cout << pow(2, n - 1) << endl;
    return 0;
}

class Solution {
public:
    vector<string> ret;
    int n;
    bool board[11] = { 0 };
    string s;
    string path;

    void dfs(int pos)
    {
        if (pos == n)
        {
            ret.push_back(path);
            return;
        }
        for (int i = 0; i < n; i++)
        {
            if (board[i])
            {
                continue;
            }
            if (i > 0 && s[i] == s[i - 1] && !board[i - 1])
            {
                continue;
            }
            path.push_back(s[i]);
            board[i] = true;
            dfs(pos + 1);
            board[i] = false;
            path.pop_back();
        }
    }

    vector<string> Permutation(string str) {
        // write code here
        n = str.size();
        sort(str.begin(), str.end());
        s = str;
        dfs(0);
        return ret;
    }
};